# Contributor: Hoang Nguyen <folliekazetani@protonmail.com>
# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=helmfile
pkgver=0.162.0
pkgrel=2
pkgdesc="Declarative spec for deploying helm charts"
url="https://helmfile.readthedocs.io/"
# armhf: ftbfs
arch="all !armhf"
license="MIT"
depends="helm"
makedepends="go"
checkdepends="bash"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/helmfile/helmfile/archive/refs/tags/v$pkgver.tar.gz"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	local _goldflags="
	-X go.szostok.io/version.version=$pkgver
	-X go.szostok.io/version.buildDate=$(date -u "+%Y-%m-%dT%H:%M:%S%z" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	-X go.szostok.io/version.commitDate=$(date -u "+%Y-%m-%dT%H:%M:%S%z" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	-X go.szostok.io/version.commit=0000000
	-X go.szostok.io/version.dirtyBuild=false
	-X github.com/helmfile/helmfile/pkg/runtime.v1Mode=true
	"
	go build -v -o helmfile -ldflags "$_goldflags"

	for shell in bash fish zsh; do
		./helmfile completion $shell > $pkgname.$shell
	done
}

check() {
	# e2e/template test requires docker
	# shellcheck disable=2046
	go test $(go list ./... | grep -v /e2e)
}

package() {
	install -Dm755 $pkgname "$pkgdir"/usr/bin/$pkgname
	install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/

	install -Dm644 helmfile.bash \
		"$pkgdir"/usr/share/bash-completion/completions/helmfile
	install -Dm644 helmfile.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_helmfile
	install -Dm644 helmfile.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/helmfile.fish
}

sha512sums="
54c114c4f1deb090e7e6b198469629c783de7638b315972320b35ba53bae95d31d18df6ee3b28ed1bca1f2eba2d6e75dd64dc45ebf4d60af9cf4281b14ab2e91  helmfile-0.162.0.tar.gz
"
